const app = getApp()
//获得全局js变量
var util = require('../../utils/util.js');
Page({
    data: {
        userInfo: null,
        rooturl: "https://www.zglianbang.com/api/miaozhimini/"
    },
    
    onLoad: function() {
        // 使用模拟数据
    },
    onShow:function(){
        if (app.globalData.ifLogin) {
            this.getUserInfo();
        }
        
    },
    detail:function(){
        wx.navigateTo({
            url: '/pages/commissionDetail/commissionDetail',
        }); 
    },
    //用户登录
    getUserInfo:function(){
        var that=this;
        var token = wx.getStorageSync('token');
        console.log(token);
        wx.request({
            url: that.data.rooturl + 'weixin/getUserInfo',
            data: {},
            header:{token:token},
            success: function (res) {
                wx.hideLoading();
                var data = res.data.data;
                that.setData({
                    userInfo: data
                })
            }
        })
    },
    
    
    // 查看团队
    viewTeam: function() {
        wx.navigateTo({
            url: '/pages/mine/team/team',
        });
    },
    
    // 查看推广码
    viewQrCode: function() {
        wx.navigateTo({
            url: '/pages/mine/qrcode/qrcode',
        });
    },
    
    // 管理银行卡
    manageBankCards: function() {
        wx.navigateTo({
            url: '/pages/mine/bankcard/bankcard',
        });
    },
    
    // 提现
    withdraw: function() {
        wx.navigateTo({
            url: '/pages/mine/withdraw/withdraw',
        });
    },
    
    // 联系客服
    contactService: function() {
        var that = this;
        wx.showModal({
            title: '联系客服',
            content: '客服热线：'+that.data.userInfo.kefu+'\n工作时间：周一至周五 9:00-18:00',
            showCancel: false,
            confirmText: '确定'
        });
    },
    
    // 关于我们
    aboutUs: function() {
        wx.navigateTo({
            url: '/pages/about/about',
        });
    },
    
    // 申请运营中心
    applyOperationCenter: function() {
        wx.navigateTo({
            url: '/pages/centerApply/centerApply',
        });
    },
    
    // 在 methods 部分添加以下方法
    
    goToProfile: function() {
      wx.navigateTo({
        url: '/pages/mine/profile/profile'
      })
    },
    
    // 如果您还没有 login 方法，可以添加如下代码
    login: function() {
      wx.navigateTo({
        url: '/pages/mine/auth/auth'
      })
    },
    logout(){
        var postdata = {
            logout:1
        }
        util.httpRrquest(app.data.rooturl + 'weixin/saveUser', 'POST',postdata)
        .then(function (response) {
            app.globalData.userinfo = [];
            app.globalData.userId = 0;
            app.globalData.userPhone = 0;
            app.globalData.ifLogin = false;
            wx.removeStorageSync('token');
            wx.showToast({
                title: '退出成功',
                icon: 'success',
                duration: 2000
            })
            setTimeout(() => {
                wx.reLaunch({
                    url: '/pages/index/index' 
                })
            }, 2000)
        }, function (error) {
            console.log(error);
        });
    },
})